package com.littlehu.system.controller;

import com.example.common.BaseDto;
import com.example.common.ResultUtils;
import com.littlehu.pojo.Article;
import com.littlehu.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.websocket.server.PathParam;
import java.util.List;

/**
 * @author littlehu
 * @data 2018/6/22 16:12
 * @Email 807115007@qq.com
 **/
@RestController
public class ArticleController {

    @Autowired
    ArticleService articleService;

    @RequestMapping("/selectId/{id}")
    public BaseDto<Article> selectId(@PathVariable("id") int id){
        return ResultUtils.success(articleService.selectById(id));
    }

    @RequestMapping("/selectByPage")
    public BaseDto<List<Article>> selectArticleByPage(@RequestParam("pageNum") int pageNum , @RequestParam("pageSize") int pageSize){
        List<Article> baseDto = articleService.selectByPage(pageNum , pageSize) ;
        if(baseDto == null || baseDto.size() == 0){
            return ResultUtils.fail(100 , "暂时无数据");
        }
        return ResultUtils.success(baseDto);
    }

    @RequestMapping("/say")
    public String say(){
        return "hello";
    }



}
